<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>订阅|PinPaper</title>
    <meta name="description" content="PinPaper|给你不一样的阅读体验">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="shortcut icon" href="/logo.png" type="image/png">
    <link rel="stylesheet" href="__PUBLIC__/css/bootstrap.css">
    <link rel="stylesheet" href="__PUBLIC__/css/font-awesome.min.css">
    <link rel="stylesheet" href="__PUBLIC__/css/style.css">
    <script src="__PUBLIC__/plugin/modernizr.custom.js"></script>
    <!--[if lt IE 9]>
    <script src="__PUBLIC__/js/ie/respond.min.js"></script>
    <script src="__PUBLIC__/js/ie/html5.js"></script>
    <![endif]-->
</head>
<body>
<section class="panel" style='margin-bottom:0px;'>
    <header class="panel-heading text-center"><h4 class='inline text-muted text-center'>订阅PinPaper</h4></header>
    <form class="padder" id='subscribe_form'>
        <div class="block">
            <volist name="tags" id="tag">
                <label class="m-b-small m-l-small btn btn-sm btn-white">
                    <input type="checkbox" name="subscribe" value="{$tag.tid}">{$tag.name}
                </label>
            </volist>
        </div>

        <div class="alert alert-warning message-alert-box" style="display: none">
            <i class="icon-bell-alt"></i><strong><span class="message-alert"></span></strong>
        </div>

        <div class="line line-dashed"></div>
        <a class="btn btn-info btn-block" id='subscribeSubmit' href="javascript:void(0);">订阅</a>
    </form>
</section>
</body>
<script src="__PUBLIC__/js/jquery.min.js"></script>
<!-- Bootstrap -->
<script src="__PUBLIC__/js/bootstrap.js"></script>

<script>
    var str = "";

    $("#subscribeSubmit").click(function () {
        $("input[name='subscribe']:checkbox").each(function () {
            if ($(this).attr("checked")) {
                str += $(this).val() + ","
            }
        });
        str = str.substring(0, str.length - 1);
        if (str == '') {
            $(".message-alert").text("请至少选择一个话题");
            $(".message-alert-box").fadeIn();
            $(".message-alert-box").fadeOut(2000);
            return false;
        }

        var data = str.split(',');

        $.ajax({
            'type': 'post',
            'data': {'subscribe': data},
            'url': "{:U('/Home/Index/subscribe')}",
            'dataType': 'json',
            success: function () {
                parent.location.reload();
            },
            error: function (e) {
                $(".message-alert").text('服务器繁忙');
                $(".message-alert-box").fadeIn();
                $(".message-alert-box").fadeOut(3000);
            }
        })
    });

</script>
</html>